<template>
	<view class="mine-view">
		<!-- <view class="vip-title-view">
			我的
		</view> -->
		<!-- 个人信息 -->
		<view class="mine">
			<image class="mine-image" v-if="from.img" @click='uploadImage' :src="img||from.img"></image>
			<image class="mine-image" @click="uploadImage" v-else src='../../static/app/touxiang.jpg' mode=""></image>
			<view class="mine-right">
				<view class="mine-right-view">
					<view class="mine-right-title">姓名: {{nick}}</view>
					<view class="mine-right-vip" v-if="member">{{member}}</view>
				</view>
				<view class="mine-right-desc">手机: {{mobile}}</view>
				<view class="mine-right-ID">上市ID:{{yjskwt}}</view>
			</view>
		</view>
		<!-- 卡片明细 -->
		<view class="mine-card-view">
			<view class="mine-card-title">
				<view class="mine-card-titleLeft">
					<view class="card-titleLeft-icon"></view>
					<view class="card-titleLeft-text">黄金分红</view>
				</view>
				<view class="card-ming-box" @click="navigatorMineDetail">明细</view>
			</view>

			<!-- 展示 -->
			<view class="card-showMessage-view">
				<view class="showMessage-view">
					<view class="showMessage-title">资产</view>
					<view class="showMessage-desc">￥{{property_money}}</view>
					<view class="showMessage-btn" @click="Withdrawal(type1,property_money,'资产')">提现</view>
				</view>
				<view class="showMessage-view">
					<view class="showMessage-title">40%分红</view>
					<view class="showMessage-desc">￥{{money}}</view>
					<view class="showMessage-btn" @click="Withdrawal(type2,money,'40%分红')">提现</view>
				</view>
				<view class="showMessage-view">
					<view class="showMessage-title">会员分红</view>
					<view class="showMessage-desc">￥{{day_money}}</view>
					<view class="showMessage-btn" @click="Withdrawal(type3,day_money,'会员分红')">提现</view>
				</view>
			</view>
			<!-- 股权 -->
			<view class="card-showMessage-zong">
				持有股权：{{sharehold}}
			</view>
			<!-- 总资 -->
			<view class="card-showMessage-zong">
				总收益：￥{{allMoney}}
			</view>
		</view>
		<!-- 常用功能 -->
		<view class="mine-list" style="background-color: #D8EBFF;">
			<view class="mine-card-title1">
				<view class="card-titleLeft-icon1" style="margin-right: 20rpx;"></view>
				<view class="card-titleLeft-text">常用功能</view>
			</view>
			<u-grid :col="4" :border="false">
				<u-grid-item bg-color="#D8EBFF" v-for="(item,index) in girdList" :key="index" @click="toUrl(item.path)">
					<image class="grid-image" :src="item.image" mode=""></image>
					<view class="grid-text" style="font-size: 14px;margin-top: 10rpx;">{{item.name}}</view>
				</u-grid-item>
			</u-grid>
			<u-grid :col="4" :border="false">
				<u-grid-item bg-color="#D8EBFF" v-for="(item,index) in girdList1" :key="index"
					@click="toUrl(item.path)">
					<image class="grid-image" :src="item.image" mode=""></image>
					<view class="grid-text" style="font-size: 14px;margin-top: 10rpx;">{{item.name}}</view>
				</u-grid-item>
			</u-grid>
		</view>
		<!-- 我的列表 -->
		<view class="mine-list">
			<view class="mine-item" v-for="(item,index) in mineList" :key="index" @click="navigatorMineList(item.path)">
				<view class="mine-item-title">{{item.name}}</view>
				<u-icon name="arrow-right"></u-icon>
			</view>
		</view>

		<!-- 底部按钮 -->
		<view class="homeInfo-message-btnView">
			<view class="homeInfo-message-btn" @click="toUrl1('/pages/login/login')">
				退出登录
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				from: {
					img: ''
				},
				img: '',
				girdList: [{
						image: '../../static/mine/1.png',
						name: '黄金证书',
						path: '/pages/mine/mine-list/gold-certificate'
					},
					{
						image: '../../static/mine/2.png',
						name: '股权证书',
						path: '/pages/mine/mine-list/share-certificate'
					},
					{
						image: '../../static/mine/3.png',
						name: '黄金分红',
						path: '/pages/mine/mine-list/dailyDividends'
					},
					{
						image: '../../static/mine/4.png',
						name: '投资记录',
						path: '/pages/order-confirm/order-list'
					}
				],
				girdList1: [{
						image: '../../static/mine/5.png',
						name: '推荐奖励',
						path: '/pages/mine/mine-list/reward'
					},
					{
						image: '../../static/mine/6.png',
						name: '地址管理',
						path: '/pages/mine/mine-list/address'
					},
					{
						image: '../../static/mine/7.png',
						name: '修改密码',
						path: '/pages/mine/mine-list/settingPassword'
					},
					{
						image: '../../static/mine/8.png',
						name: '产品奖励',
						path: '/pages/mine/mine-list/productRewards'
					}
				],
				mineList: [{
						name: '我的团队',
						path: '/pages/mine/mine-list/myTeam'
					},
					{
						name: '我的保障金',
						path: '/pages/mine/mine-list/security'
					},
					{
						name: '官方客服',
						path: '/pages/mine/mine-list/customerService'
					},
					{
						name: '提现记录',
						path: '/pages/mine/mine-list/withdrawalRecords'
					},
					{
						name: '推广中心',
						path: '/pages/mine/mine-list/promotionCenter'
					},
				],
				nick: '',
				mobile: '',
				property_money: 0,
				money: 0,
				day_money: 0,
				type1: 1,
				type2: 2,
				type3: 3,
				member: '',
				yjskwt: 0,
				allMoney: 0,
				sharehold: 0,
				allowance_money: 0
			};
		},
		onShow() {
			this.getUserInfo()
		},
		methods: {
			...mapMutations(['logout']),
			toUrl(path) {
				uni.navigateTo({
					url: path
				})
			},
			toUrl1(path) {
				uni.removeStorageSync('loginStatus')
				uni.removeStorageSync('token')
				uni.navigateTo({
					url: path
				})
			},
			navigatorMineDetail() {
				uni.navigateTo({
					url: '/pages/mine/mine-detail/mine-detail'
				})
			},
			getUserInfo() {
				this.$http.post(this.$api.getUserInfo, {}, {
					token: true
				}).then(res => {
					console.log(res)
					this.nick = res.data.nick
					this.mobile = res.data.mobile
					this.property_money = res.data.property_money
					this.money = res.data.money
					this.day_money = res.data.day_money
					this.member = res.data.member
					this.yjskwt = res.data.yjskwt
					this.from.img = res.data.avatar
					this.sharehold = res.data.sharehold
					this.allowance_money = res.data.allowance_money
					let allMoney = (parseInt(this.property_money) + parseInt(this.money) + parseInt(this
						.day_money)).toFixed(0)
					if (allMoney) {
						this.allMoney = allMoney
					}
				})
			},
			navigatorMineList(path) {
				console.log(path)
				if (path == '/pages/login/login') {
					this.logout()
					uni.showToast({
						title: '退出登录成功'
					})
					return uni.navigateTo({
						url: path
					})
				}
				if (path == '/pages/mine/mine-list/security') {
					return uni.navigateTo({
						url: '/pages/mine/mine-list/security?allowance_money=' + this.allowance_money
					})
				}
				uni.navigateTo({
					url: path
				})
			},
			Withdrawal(type, amount, name) {
				uni.navigateTo({
					url: '/pages/mine/mine-list/Withdrawal?type=' + type + '&name=' + name + '&amount=' + amount
				})
			},
			uploadImage() {
				let that = this;
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'],
					success: function(res) {
						this.img =
							uni.uploadFile({
								url: that.$api.upload + '/Image/upload',
								filePath: res.tempFilePaths[0],
								name: 'image',
								header: {
									'token': uni.getStorageSync('token'),
								},
								success: res => {
									let result = JSON.parse(res.data);
									that.from.img = result.data.src;
									that.img = that.$api.uploadImage + result.data.src
									that.setAvatar()
								}
							});
					}
				});
			},
			setAvatar() {
				this.$http.post(this.$api.setAvatar, {
					avatar: this.from.img
				}, {
					token: true
				}).then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: '头像上传成功'
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	// 底部按钮
	.homeInfo-message-btnView {
		width: 100%;
		padding: 20rpx 30rpx;

		.homeInfo-message-btn {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100%;
			padding: 20rpx 0;
			background: #E1E1E1;
			border-radius: 20rpx;
			font-size: 15px;
			color: #999999;
		}
	}

	.grid-image {
		width: 80rpx;
		height: 80rpx;
	}

	.mine-list {
		background-color: #D8EBFF;
		border-radius: 30rpx;
		padding: 30rpx 30rpx 0 30rpx;
		margin: 30rpx 0;

		.mine-item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			// border-bottom: 1px solid #E7E7E7;
			padding: 20rpx 0;

			.mine-item-title {
				font-size: 15px;
				color: #333333;
			}
		}

		.mine-item:last-child {
			border-bottom: 0;
		}

		.mine-item:first-child {
			padding-top: 0;
		}
	}

	.card-showMessage-zong {
		font-size: 17px;
		color: #ffffff;
		padding-top: 30rpx;
	}

	.card-showMessage-view {
		display: flex;
		align-items: center;
		margin-top: 50rpx;
		padding-bottom: 30rpx;
		border-bottom: 1px solid #666666;

		.showMessage-view {
			flex: 1;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			margin-right: 10rpx;

			.showMessage-title {
				font-size: 15px;
				color: #ffffff;
				margin-bottom: 10rpx;
			}

			.showMessage-desc {
				font-size: 15px;
				color: #ffffff;
				margin-bottom: 10rpx;
			}

			.showMessage-btn {
				background: url('../../static/mine/40.png')no-repeat;
				background-size: 100% 100%;
				padding: 5rpx 30rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 13px;
				color: #333333;
			}
		}
	}

	.card-titleLeft-icon1 {
		width: 4rpx;
		height: 25rpx;
		background-color: #333333;
		border-radius: 2rpx;
		margin-right: 10rpx;
		margin-top: 5rpx;
	}

	.mine-card-title1 {
		display: flex;
		align-items: center;
	}

	.mine-card-view {
		background: url('../../static/mine/39.png') no-repeat;
		background-size: 100% 100%;
		border-radius: 30rpx;
		padding: 30rpx;
		margin-top: 30rpx;
		position: relative;

		.mine-card-title {
			.mine-card-titleLeft {
				display: flex;
				align-items: center;

				.card-titleLeft-icon {
					width: 4rpx;
					height: 25rpx;
					background-color: #ffffff;
					border-radius: 2rpx;
					margin-right: 10rpx;
					margin-top: 5rpx;
				}

				.card-titleLeft-text {
					font-size: 17px;
					color: #ffffff;
				}
			}

			.card-ming-box {
				position: absolute;
				top: 30rpx;
				right: 0;
				width: 120rpx;
				height: 52rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 28rpx 0px 0px 28rpx;
				background-color: rgba(102, 102, 102, 0.6);
				font-size: 15px;
				color: #ffffff;
			}
		}
	}

	.mine {
		display: flex;
		align-items: center;
		margin-top: 60rpx;

		.mine-image {
			width: 150rpx;
			height: 150rpx;
			margin-right: 30rpx;
			border-radius: 150rpx;
			flex-shrink: 0;
		}

		.mine-right {
			flex: 1;

			.mine-right-view {
				display: flex;
				align-items: center;
				margin-bottom: 10rpx;

				.mine-right-title {
					font-size: 18px;
					color: #ffffff;
				}

				.mine-right-vip {
					// width: 130rpx;
					height: 40rpx;
					text-align: center;
					line-height: 20rpx;
					font-size: 10px;
					padding: 10rpx 20rpx;
					color: #333333;
					background: url('../../static/mine/38.png') no-repeat;
					background-size: 100% 40rpx;
					margin-left: 20rpx;
				}
			}

			.mine-right-desc {
				font-size: 18px;
				color: #ffffff;
				margin-bottom: 10rpx;
			}

			.mine-right-ID {
				font-size: 18px;
				color: #ffffff;
			}

		}
	}

	.mine-view {
		padding: 30rpx;
		background: linear-gradient(180deg, #2776F6 0%, rgba(51, 120, 231, 0.00) 50%);
		background-blend-mode: multiply;
	}

	.vip-title-view {
		display: flex;
		align-items: center;
		justify-content: center;
		color: #ffffff;
		font-size: 18px;
		margin-bottom: 30rpx;
	}
</style>